package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.PcmcDataPermission;
import com.core.zyyz.pcmc.service.PcmcDataPermissionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 数据权限Controller
 *
 * @author core
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/pcmc/dataPermission")
public class PcmcDataPermissionController extends BaseController
{
    @Autowired
    private PcmcDataPermissionService pcmcDataPermissionService;

    /**
     * 查询数据权限列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcDataPermission pcmcDataPermission)
    {
        startPage();
        List<PcmcDataPermission> list = pcmcDataPermissionService.selectPcmcDataPermissionList(pcmcDataPermission);
        return getDataTable(list);
    }

    /**
     * 导出数据权限列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:export')")
    @Log(title = "数据权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcDataPermission pcmcDataPermission)
    {
        List<PcmcDataPermission> list = pcmcDataPermissionService.selectPcmcDataPermissionList(pcmcDataPermission);
        ExcelUtil<PcmcDataPermission> util = new ExcelUtil<PcmcDataPermission>(PcmcDataPermission.class);
        util.exportExcel(response, list, "数据权限数据");
    }

    /**
     * 获取数据权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:query')")
    @GetMapping(value = "/{dataPermId}")
    public AjaxResult getInfo(@PathVariable("dataPermId") Long dataPermId)
    {
        return success(pcmcDataPermissionService.selectPcmcDataPermissionByDataPermId(dataPermId));
    }

    /**
     * 新增数据权限
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:add')")
    @Log(title = "数据权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcDataPermission pcmcDataPermission)
    {
        return toAjax(pcmcDataPermissionService.insertPcmcDataPermission(pcmcDataPermission));
    }

    /**
     * 修改数据权限
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:edit')")
    @Log(title = "数据权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcDataPermission pcmcDataPermission)
    {
        return toAjax(pcmcDataPermissionService.updatePcmcDataPermission(pcmcDataPermission));
    }

    /**
     * 删除数据权限
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataPermission:remove')")
    @Log(title = "数据权限", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataPermIds}")
    public AjaxResult remove(@PathVariable Long[] dataPermIds)
    {
        return toAjax(pcmcDataPermissionService.deletePcmcDataPermissionByDataPermIds(dataPermIds));
    }
}
